package kr.hkit.androidcomplete02.fragment;

import kr.hkit.androidcomplete02.R;
import kr.hkit.androidcomplete02.fragment.FragmentEx.CounterFragment;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;

public class BackStack extends Activity {
	
	int mStart = 10;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.backstack);
		
		if(savedInstanceState != null) {
			mStart = savedInstanceState.getInt("mStart");
		}
		
		CounterFragment cf = new CounterFragment();
		Bundle args = new Bundle();
		args.putInt("start", mStart);
		cf.setArguments(args);
		getFragmentManager().beginTransaction().add(R.id.frame, cf).commit();
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		
		outState.putInt("start", mStart);
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.btnadd:
			mStart +=10;
			FragmentTransaction tr = getFragmentManager().beginTransaction();
			CounterFragment cf = new CounterFragment();
			Bundle args = new Bundle();
			args.putInt("start", mStart);
			cf.setArguments(args);
			tr.replace(R.id.frame, cf);
			tr.addToBackStack(null);
			tr.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
			tr.commit();
			break;
		}
	}

}
